package silo.dungeonbuddy;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.io.File;

import javax.swing.JFileChooser;

public class StatsForm extends Form
{
	private int type;
	private Unit unit;
	private Terrain terrain;
	private Marker marker;
	private Object object;
	private Effect effect;
	
	public StatsForm(String eName, Start eGame, int eX, int eY, int eWidth, int eHeight, String eTitle, FlatImage eItem)
	{
		super(eName,eGame,eX,eY,eWidth,eHeight,eTitle);
		type=0;
		try
		{
			unit = (Unit)eItem;
			type=1;
		}catch(Exception e)
		{
			try
			{
				terrain = (Terrain)eItem;
				type=2;
			}catch(Exception e2)
			{
				try
				{
					marker = (Marker)eItem;
					type=3;
				}catch(Exception e3)
				{
					try
					{
						object = (Object)eItem;
						type=4;
					}catch(Exception e4)
					{
						try
						{
							effect = (Effect)eItem;
							type=5;
						}catch(Exception e5)
						{
							type=6;
						}
					}
				}
			}
		}
		Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
		if(game.getClient())
		{
			buildForClient(g);
		}else
		{
			buildForServer(g);
		}
	}//constructor
	
	private void buildForClient(Graphics2D g)
	{
		if(type==1)
		{
			String refLG = "";
			int k=0;
			while(unit.getRef().charAt(k)!='/')
			{
				k=k+1;
			}//loop
			k=k+1;
			while(unit.getRef().charAt(k)!='.')
			{
				refLG = refLG + unit.getRef().charAt(k);
				k=k+1;
			}//loop
			String extension = "";
			while(k<unit.getRef().length())
			{
				extension = extension + unit.getRef().charAt(k);
				k=k+1;
			}//loop
			refLG = refLG + "LG" + extension;
			File dir = new File("./sprites/");
			String[] children = dir.list();
			boolean LG = false;
			if(children == null)
			{
				// Either dir does not exist or is not a directory
			}else//if(children == null)
			{
				for (int i=0; i<children.length; i++)
				{
					// Get filename of file or directory
					String filename = children[i];
					if(filename.equals(refLG))
					{
						LG=true;
						i=children.length;
					}//if(filename.equals(refLG))
				}//next i
			}//else -- if(children == null)
			if(LG)
			{
				images.add(new FormImage("img" + unit.getName(),"sprites/" + refLG,game,10,35,180,180));
			}else//if(LG)
			{
				images.add(new FormImage("img" + unit.getName(),unit.getRef(),game,10,35,180,180));
			}//else -- if(LG)
			FormImage m = (FormImage)images.get(images.size()-1);
			m.setOnBoard(false);
			labels.add(new Label("lblName", unit.getName(), 5, 20, 60, 20, true));
			if(game.getMyUnit().getTurn()==1)
			{
				buttons.add(new Button(game,300,370,true,0,"Attack this unit",Color.getHSBColor(57, 52, 84),g,true));
			}else
			{
				buttons.add(new Button(game,300,370,true,0,"Attack this unit",Color.getHSBColor(57, 52, 84),g,false));
			}
			if(unit==game.getMyUnit())
			{
				labels.add(new Label("lblHP", "" + unit.getHp(), 200, 40, 60, 20, true));
			}
		}else if(type==2)
		{
			String refLG = "";
			int k=0;
			while(terrain.getRef().charAt(k)!='/')
			{
				k=k+1;
			}//loop
			k=k+1;
			while(terrain.getRef().charAt(k)!='.')
			{
				refLG = refLG + terrain.getRef().charAt(k);
				k=k+1;
			}//loop
			String extension = "";
			while(k<terrain.getRef().length())
			{
				extension = extension + terrain.getRef().charAt(k);
				k=k+1;
			}//loop
			refLG = refLG + "LG" + extension;
			File dir = new File("./sprites/");
			String[] children = dir.list();
			boolean LG = false;
			if(children == null)
			{
				// Either dir does not exist or is not a directory
			}else//if(children == null)
			{
				for (int i=0; i<children.length; i++)
				{
					// Get filename of file or directory
					String filename = children[i];
					if(filename.equals(refLG))
					{
						LG=true;
						i=children.length;
					}//if(filename.equals(refLG))
				}//next i
			}//else -- if(children == null)
			if(LG)
			{
				images.add(new FormImage("img" + terrain.getName(),"sprites/" + refLG,game,10,5,180,180));
			}else//if(LG)
			{
				images.add(new FormImage("img" + terrain.getName(),terrain.getRef(),game,10,5,180,180));
			}//else -- if(LG)
			FormImage m = (FormImage)images.get(images.size()-1);
			m.setOnBoard(false);
		}else if(type == 3)
		{
			String refLG = "";
			int k=0;
			while(marker.getRef().charAt(k)!='/')
			{
				k=k+1;
			}//loop
			k=k+1;
			while(marker.getRef().charAt(k)!='.')
			{
				refLG = refLG + marker.getRef().charAt(k);
				k=k+1;
			}//loop
			String extension = "";
			while(k<marker.getRef().length())
			{
				extension = extension + marker.getRef().charAt(k);
				k=k+1;
			}//loop
			refLG = refLG + "LG" + extension;
			File dir = new File("./sprites/");
			String[] children = dir.list();
			boolean LG = false;
			if(children == null)
			{
				// Either dir does not exist or is not a directory
			}else//if(children == null)
			{
				for (int i=0; i<children.length; i++)
				{
					// Get filename of file or directory
					String filename = children[i];
					if(filename.equals(refLG))
					{
						LG=true;
						i=children.length;
					}//if(filename.equals(refLG))
				}//next i
			}//else -- if(children == null)
			if(LG)
			{
				images.add(new FormImage("img" + marker.getName(),"sprites/" + refLG,game,10,45,180,180));
			}else//if(LG)
			{
				images.add(new FormImage("img" + marker.getName(),marker.getRef(),game,10,45,180,180));
			}//else -- if(LG)
			//images.add(new FormImage("img" + marker.getName(),marker.getRef(),game,10,45,180,180));
			FormImage m = (FormImage)images.get(images.size()-1);
			m.setOnBoard(false);
			labels.add(new Label("lblName", marker.getName(), 5, 20, 60, 20, true));
		}else
		{
			images.add(new FormImage("img" + "??","sprites/default.png",game,10,5,180,180));
			FormImage m = (FormImage)images.get(images.size()-1);
			m.setOnBoard(false);
		}
	}//buildForClient
	
	private void buildForServer(Graphics2D g)
	{
		if(type==1)
		{
			String refLG = "";
			int k=0;
			while(unit.getRef().charAt(k)!='/')
			{
				k=k+1;
			}//loop
			k=k+1;
			while(unit.getRef().charAt(k)!='.')
			{
				refLG = refLG + unit.getRef().charAt(k);
				k=k+1;
			}//loop
			String extension = "";
			while(k<unit.getRef().length())
			{
				extension = extension + unit.getRef().charAt(k);
				k=k+1;
			}//loop
			refLG = refLG + "LG" + extension;
			File dir = new File("./sprites/");
			String[] children = dir.list();
			boolean LG = false;
			if(children == null)
			{
				// Either dir does not exist or is not a directory
			}else//if(children == null)
			{
				for (int i=0; i<children.length; i++)
				{
					// Get filename of file or directory
					String filename = children[i];
					if(filename.equals(refLG))
					{
						LG=true;
						i=children.length;
					}//if(filename.equals(refLG))
				}//next i
			}//else -- if(children == null)
			if(LG)
			{
				images.add(new FormImage("img" + unit.getName(),"sprites/" + refLG,game,10,45,180,180));
			}else//if(LG)
			{
				images.add(new FormImage("img" + unit.getName(),unit.getRef(),game,10,45,180,180));
			}//else -- if(LG)
			FormImage m = (FormImage)images.get(images.size()-1);
			m.setOnBoard(false);
			
			//labels.add(new Label("lblName", unit.getName(), 5, 20, 60, 20, true));
			textBoxes.add(new TextBox("Name",10,15,180,20,true,0));
			TextBox t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getName());
			
			//FIRST COLUMN
			textBoxes.add(new TextBox("Hp",200,15,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getHp());
			textBoxes.add(new TextBox("MaxHp",200,55,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getMaxHp());
			textBoxes.add(new TextBox("AC",200,95,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getAC());
			textBoxes.add(new TextBox("Fortitude",200,135,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getFortitude());
			textBoxes.add(new TextBox("Reflex",200,175,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getReflex());
			textBoxes.add(new TextBox("Will",200,215,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getWill());
			
			
			
			//SECOND COLUMN
			textBoxes.add(new TextBox("Strength",270,15,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getStrength());
			textBoxes.add(new TextBox("Constitution",270,55,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getConstitution());
			textBoxes.add(new TextBox("Dexterity",270,95,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getDex());
			textBoxes.add(new TextBox("Intelligence",270,135,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getIntelligence());
			textBoxes.add(new TextBox("Wisdom",270,175,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getWisdom());
			textBoxes.add(new TextBox("Charisma",270,215,60,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getCharisma());
			
			//THIRD COLUMN
			textBoxes.add(new TextBox("Initiative",340,15,50,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getInitiative());
			textBoxes.add(new TextBox("Perception",340,55,50,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getPerception());
			textBoxes.add(new TextBox("Stealth",340,95,50,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getStealth());
			textBoxes.add(new TextBox("Weapon",340,135,50,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getMagicWeapon());
			textBoxes.add(new TextBox("Implement",340,175,50,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getMagicImplement());
			textBoxes.add(new TextBox("Proficiency",340,215,50,20,true,0));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getWeaponProficiency());
			
			
			textBoxes.add(new TextBox("Owner",10,240,175,20,true,16));
			t = (TextBox)textBoxes.get(textBoxes.size()-1);
			t.setText("" + unit.getOwner());
			labels.add(new Label("lblCheckBoxes", "To hide this unit from a player, check their box below:", 5, 285,width-6,20,true));
			if(game.getClientList().size()>0)
			{
				for(int i=0; i<game.getClientList().size(); i++)
				{
					ClientPlayer c = (ClientPlayer)game.getClientList().get(i);
					int cX = 0;
					int cY = 0;
					if(i==0)
					{
						cX = 10;
						cY = 305;
					}else//if(i==0)
					{
						CheckBox cK = (CheckBox)checkBoxes.get(checkBoxes.size()-1);
						cX=cK.getX() + g.getFontMetrics().stringWidth(cK.getLabel()) + 30;
						cY=cK.getY();
						if((cX+g.getFontMetrics().stringWidth(cK.getLabel())+13)>=width)
						{
							cX = 10;
							cY = cY+20;
						}//if((cX+13)>=width)
					}//else -- if(i==0)
					if((cX+13)>=width)
					{
						cX = 10;
					}//if((cX+13)>=width)
					if(unit.getForceHideList().contains(c))
					{
						checkBoxes.add(new CheckBox("chk" + c.getUserName(),cX,cY,true,c.getUserName()));
					}else//if(unit.getForceHideList().contains(c))
					{
						checkBoxes.add(new CheckBox("chk" + c.getUserName(),cX,cY,false,c.getUserName()));
					}//else -- if(unit.getForceHideList().contains(c))
				}//next i
			}//if(game.getClientList().size()>0)
			buttons.add(new Button(game,310,370,true,0,"Confirm edits",Color.getHSBColor(57, 52, 84),g,true));
			buttons.add(new Button(game,230,370,true,0,"Save piece",Color.getHSBColor(57, 52, 84),g,true));
			buttons.add(new Button(game,5,370,true,0,"Damage this unit",Color.getHSBColor(57, 52, 84),g,true));
		}else if(type == 2)
		{
			String refLG = "";
			int k=0;
			while(terrain.getRef().charAt(k)!='/')
			{
				k=k+1;
			}//loop
			k=k+1;
			while(terrain.getRef().charAt(k)!='.')
			{
				refLG = refLG + terrain.getRef().charAt(k);
				k=k+1;
			}//loop
			String extension = "";
			while(k<terrain.getRef().length())
			{
				extension = extension + terrain.getRef().charAt(k);
				k=k+1;
			}//loop
			refLG = refLG + "LG" + extension;
			File dir = new File("./sprites/");
			String[] children = dir.list();
			boolean LG = false;
			if(children == null)
			{
				// Either dir does not exist or is not a directory
			}else//if(children == null)
			{
				for (int i=0; i<children.length; i++)
				{
					// Get filename of file or directory
					String filename = children[i];
					if(filename.equals(refLG))
					{
						LG=true;
						i=children.length;
					}//if(filename.equals(refLG))
				}//next i
			}//else -- if(children == null)
			if(LG)
			{
				images.add(new FormImage("img" + terrain.getName(),"sprites/" + refLG,game,10,45,180,180));
			}else//if(LG)
			{
				images.add(new FormImage("img" + terrain.getName(),terrain.getRef(),game,10,45,180,180));
			}//else -- if(LG)
			FormImage m = (FormImage)images.get(images.size()-1);
			m.setOnBoard(false);
			labels.add(new Label("lblName", terrain.getName(), 5, 20, 60, 20, true));
			labels.add(new Label("lblOwner", "Owner: " + "Terrain", 5, 240, 60, 20, true));
		}else if(type == 3)
		{
			String refLG = "";
			int k=0;
			while(marker.getRef().charAt(k)!='/')
			{
				k=k+1;
			}//loop
			k=k+1;
			while(marker.getRef().charAt(k)!='.')
			{
				refLG = refLG + marker.getRef().charAt(k);
				k=k+1;
			}//loop
			String extension = "";
			while(k<marker.getRef().length())
			{
				extension = extension + marker.getRef().charAt(k);
				k=k+1;
			}//loop
			refLG = refLG + "LG" + extension;
			File dir = new File("./sprites/");
			String[] children = dir.list();
			boolean LG = false;
			if(children == null)
			{
				// Either dir does not exist or is not a directory
			}else//if(children == null)
			{
				for (int i=0; i<children.length; i++)
				{
					// Get filename of file or directory
					String filename = children[i];
					if(filename.equals(refLG))
					{
						LG=true;
						i=children.length;
					}//if(filename.equals(refLG))
				}//next i
			}//else -- if(children == null)
			if(LG)
			{
				images.add(new FormImage("img" + marker.getName(),"sprites/" + refLG,game,10,45,180,180));
			}else//if(LG)
			{
				images.add(new FormImage("img" + marker.getName(),marker.getRef(),game,10,45,180,180));
			}//else -- if(LG)
			//images.add(new FormImage("img" + marker.getName(),marker.getRef(),game,10,45,180,180));
			FormImage m = (FormImage)images.get(images.size()-1);
			m.setOnBoard(false);
			labels.add(new Label("lblName", marker.getName(), 5, 20, 60, 20, true));
			labels.add(new Label("lblOwner", "Owner: " + "none", 5, 240, 60, 20, true));
		}else
		{
			images.add(new FormImage("img" + "??","sprites/default.png",game,10,45,180,180));
			FormImage m = (FormImage)images.get(images.size()-1);
			m.setOnBoard(false);
			labels.add(new Label("lblName", "??", 5, 20, 60, 20, true));
			labels.add(new Label("lblOwner", "Owner: " + "??", 5, 240, 60, 20, true));
		}
	}//buildForServer
	
	protected void checkMouse()
	{
		if((doubleClick)&&(!game.getClient()))
		{
			FormImage im = (FormImage)images.get(0);
			if((mouseX>im.getX())&&(mouseX<(im.getX()+im.getSizeX()))&&(mouseY>im.getY())&&(mouseY<(im.getY()+im.getSizeY())))
			{
				if(type==1)
				{
					JFileChooser fc = new JFileChooser();
					File dir = new File("./sprites/");
					fc.setCurrentDirectory(dir);
					fc.showOpenDialog(fc);
					if(fc.getSelectedFile()!=null)
					{
						try
						{
							unit.changeImage("sprites/" + fc.getName(fc.getSelectedFile()));
							unit.setMoved(true);
							im.changeImage("sprites/" + fc.getName(fc.getSelectedFile()));
						}catch(Exception e)
						{
							//nothing for non-units
						}//catch e
					}//if(fc.getSelectedFile()!=null)
				}else if(type==2)//if(type==1)
				{
					JFileChooser fc = new JFileChooser();
					File dir = new File("./sprites/");
					fc.setCurrentDirectory(dir);
					fc.showOpenDialog(fc);
					if(fc.getSelectedFile()!=null)
					{
						try
						{
							terrain.changeImage("sprites/" + fc.getName(fc.getSelectedFile()));
							im.changeImage("sprites/" + fc.getName(fc.getSelectedFile()));
						}catch(Exception e)
						{
							//nothing for non-units
						}//catch e
					}//if(fc.getSelectedFile()!=null)
				}//else if(type==2) -- if(type==1)
			}//if((mouseX>im.getX())&&(mouseX<(im.getX()+im.getSizeX()))&&(mouseY>im.getY())&&(mouseY<(im.getY()+im.getSizeY())))
			doubleClick=false;
		}else if((!game.getClient())&&(mouseLeft)&&(checkBoxes.size()>0))//if((doubleClick)&&(!game.getClient()))
		{
			for(int i=0; i<checkBoxes.size(); i++)
			{
				CheckBox cK = (CheckBox)checkBoxes.get(i);
				if((mouseX>cK.getX())&&(mouseX<cK.getX()+12)&&(mouseY>cK.getY())&&(mouseY<cK.getY()+12))
				{
					if(cK.getSelected())
					{
						cK.setSelected(false);
					}else
					{
						cK.setSelected(true);
					}
					i=checkBoxes.size();
				}//if((mouseX>cK.getX())&&(mouseX<cK.getX()+12)&&(mouseY>cK.getY())&&(mouseY<cK.getY()+12))
			}//next i
			mouseLeft=false;
		}//else if(!game.getClient()) -- if((doubleClick)&&(!game.getClient()))
	}//protected void checkMouse()
	
	public void draw()
	{
		// GET CONTEXT FOR ACCELERATED GRAPHICS
		Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
		g.setColor(Color.gray);
		g.fillRect(0,0,width,height);
		if(textBoxes.size()>0)
		{
			for(int i=0;i<textBoxes.size();i++)
			{
				TextBox t = (TextBox)textBoxes.get(i);
				t.draw(g);
			}//next i
		}//if(textBoxes.size()>0)
		if(buttons.size()>0)
		{
			for(int i=0;i<buttons.size();i++)
			{
				Button b = (Button)buttons.get(i);
				b.draw(g);
			}//next i
		}//if(buttons.size()>0)
		if(checkBoxes.size()>0)
		{
			for(int i=0; i<checkBoxes.size(); i++)
			{
				CheckBox c = (CheckBox)checkBoxes.get(i);
				c.draw(g);
			}//next i
		}//if(checkBoxes.size()>0)
		if(labels.size()>0)
		{
			for(int i=0;i<labels.size();i++)
			{
				Label l = (Label)labels.get(i);
				l.draw(g);
			}//next i
		}//if(labels.size()>0)
		if(images.size()>0)
		{
			for(int i=0;i<images.size();i++)
			{
				FlatImage f = (FlatImage)images.get(i);
				f.draw(g);
			}//next i
		}//if(images.size()>0)
		
		//Draw HP bar
		if((type==1)&&(game.getClient()))
		{
			for(int i=0;i<labels.size();i++)
			{
				Label l = (Label)labels.get(i);
				if(l.getName().equals("lblHP"))
				{
					l.setText("" + unit.getHp());
					i=labels.size();
				}//if(l.getName().equals("lblHP"))
			}//next i
			g.setColor(Color.black);
			g.drawRect(9,30,181,10);
			g.setColor(Color.gray);
			g.fillRect(10,31,180,9);
			if(((float)((float)unit.getHp()/(float)unit.getMaxHp())<=1)&&((float)((float)unit.getHp()/(float)unit.getMaxHp())>=0)&&(unit.getHp()>0))
			{
				if((float)((float)unit.getHp()/(float)unit.getMaxHp())<=0.5)
				{
					g.setColor(Color.orange);
				}else
				{
					g.setColor(Color.green);
				}
				g.fillRect(10,31,(int)(180*(float)((float)unit.getHp()/(float)unit.getMaxHp())),9);
			}else if((float)((float)unit.getHp()/(float)unit.getMaxHp())>1)//if(((float)((float)unit.getHp()/(float)unit.getMaxHp())<=1)&&((float)((float)unit.getHp()/(float)unit.getMaxHp())>=0)&&(unit.getHp()>0))
			{
				if((float)((float)unit.getHp()/(float)unit.getMaxHp())<=2)
				{
					g.setColor(Color.green);
					g.fillRect(10,31,180,9);
					g.setColor(new Color(255,255,255,225));
					g.fillRect(10,31,(int)(180*(float)(((float)unit.getHp()/(float)unit.getMaxHp())-1)),9);
				}else//if((float)((float)unit.getHp()/(float)unit.getMaxHp())<=2)
				{
					g.setColor(Color.green);
					g.fillRect(10,31,180,9);
					g.setColor(new Color(255,255,255,225));
					g.fillRect(10,31,180,9);
				}
			}else if(unit.getHp()<0)//else if((float)((float)unit.getHp()/(float)unit.getMaxHp())>1) -- if(((float)((float)unit.getHp()/(float)unit.getMaxHp())<=1)&&((float)((float)unit.getHp()/(float)unit.getMaxHp())>=0)&&(unit.getHp()>0))
			{
				if((0-unit.getHp())<(int)((float)unit.getMaxHp()/(float)2))
				{
					g.setColor(Color.red);
					g.fillRect(10,31,(int)(-180*2*(float)((float)unit.getHp()/(float)unit.getMaxHp())),9);
				}else
				{
					g.setColor(Color.red);
					g.fillRect(10,31,180,9);
				}
			}
			g.setColor(new Color(255,255,255,200));
			g.fillRect(10,31,180,4);
		}else if(type==1)//if((type==1)&&(game.getClient()))
		{
			g.setColor(Color.black);
			g.drawRect(9,40,181,10);
			g.setColor(Color.gray);
			g.fillRect(10,41,180,9);
			if(((float)((float)unit.getHp()/(float)unit.getMaxHp())<=1)&&((float)((float)unit.getHp()/(float)unit.getMaxHp())>=0)&&(unit.getHp()>0))
			{
				if((float)((float)unit.getHp()/(float)unit.getMaxHp())<=0.5)
				{
					g.setColor(Color.orange);
				}else
				{
					g.setColor(Color.green);
				}
				g.fillRect(10,41,(int)(180*(float)((float)unit.getHp()/(float)unit.getMaxHp())),9);
			}else if((float)((float)unit.getHp()/(float)unit.getMaxHp())>1)//if(((float)((float)unit.getHp()/(float)unit.getMaxHp())<=1)&&((float)((float)unit.getHp()/(float)unit.getMaxHp())>=0)&&(unit.getHp()>0))
			{
				if((float)((float)unit.getHp()/(float)unit.getMaxHp())<=2)
				{
					g.setColor(Color.green);
					g.fillRect(10,41,180,9);
					g.setColor(new Color(255,255,255,225));
					g.fillRect(10,41,(int)(180*(float)(((float)unit.getHp()/(float)unit.getMaxHp())-1)),9);
				}else//if((float)((float)unit.getHp()/(float)unit.getMaxHp())<=2)
				{
					g.setColor(Color.green);
					g.fillRect(10,41,180,9);
					g.setColor(new Color(255,255,255,225));
					g.fillRect(10,41,180,9);
				}
			}else if(unit.getHp()<0)//else if((float)((float)unit.getHp()/(float)unit.getMaxHp())>1) -- if(((float)((float)unit.getHp()/(float)unit.getMaxHp())<=1)&&((float)((float)unit.getHp()/(float)unit.getMaxHp())>=0)&&(unit.getHp()>0))
			{
				if((0-unit.getHp())<(int)((float)unit.getMaxHp()/(float)2))
				{
					g.setColor(Color.red);
					g.fillRect(10,41,(int)(-180*2*(float)((float)unit.getHp()/(float)unit.getMaxHp())),9);
				}else
				{
					g.setColor(Color.red);
					g.fillRect(10,41,180,9);
				}
			}
			g.setColor(new Color(255,255,255,200));
			g.fillRect(10,41,180,4);
		}//else if(type==1) -- if((type==1)&&(game.getClient()))
		
		//DISPOSE OF GRAPHICS OBJECT AND FLIP BUFFER
		g.dispose();
		strategy.show();
	}//draw

	//GETTERS
	public Unit getUnit()
	{
		return unit;
	}
	public Terrain getTerrain()
	{
		return terrain;
	}
	public Marker getMarker()
	{
		return marker;
	}
	public Object getObject()
	{
		return object;
	}
	public Effect getEffect()
	{
		return effect;
	}
	public int getType()
	{
		return type;
	}
	
	//SETTERS
	public void setUnit(Unit eUnit)
	{
		unit=eUnit;
	}
	
}//class StatsForm